package cn.yunhe;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class FenYe extends BaseDB {
    static Connection conn = null;
    static PreparedStatement psmt = null;
    static ResultSet rs = null;
    //public static final int pageNum = 3;

    /**
     * 返回总条数
     *
     * @return
     */
    public static int boardCount(String sql) {
        int count = 0;
        try {
            conn = getConn();
            psmt = conn.prepareStatement(sql);
            rs = psmt.executeQuery();
            if (rs.next())
                count = rs.getInt(1);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            closeAll(conn,psmt,rs);
        }

        return count;
    }

    /**
     * 返回总页数
     *
     * @param count   总条数
     * @param pageNum 每页显示的条数
     * @return
     */
    public static int pageSize(int count, int pageNum) {
        return count % pageNum == 0 ? count / pageNum : (count / pageNum) + 1;
    }
}
